using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Log : MonoBehaviour
{
    public Text textLog;
    private string totalString = "";
    private int index;

    void OnEnable()
    {
        Application.logMessageReceived += LogMessage;
    }

    void OnDisable()
    {
        Application.logMessageReceived -= LogMessage;
    }

    public void LogMessage(string message, string stackTrace, LogType type)
    {
        totalString += $"\n 第{index}条： \n   {type} \n   {message}  \n   {stackTrace}";
        if (textLog != null)
        {
            textLog.text = totalString;
        }        
        index++;
    }

    private void OnDestroy()
    {
        var path = "";
        var now = System.DateTime.Now.ToString().Replace(":","_").Replace("/","-");     
        path = @$"D:/Unity日志文件{now}.txt";
        System.IO.File.WriteAllText(path,totalString);
    }

}
